package com.wgchao.customer;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: RequestHeaderInterceptor
 * @author: wgchao
 * @createTime: 2019/8/9 2:52 PM
 * @Description: 把RootContext中的XID（XID用于标识一个局部事务属于哪个全局事务，
 * 需要在调用链路的上下文中传递）传递到上层调用链路
 */
@Configuration
public class RequestHeaderInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template) {
        String xid = RootContext.getXID();
        if(StringUtils.isNotBlank(xid)){
            template.header("Fescar-Xid",xid);
        }
    }
}
